package com.lej.stethomodule;

import android.content.Context;
import android.util.Log;

import java.lang.reflect.Method;

import okhttp3.Interceptor;

public class StethoUtils {

    public static void init(Context context) {
        try {
            Class<?> stethoClass = Class.forName("com.facebook.stetho.Stetho");
            Method initializeWithDefaults = stethoClass.getMethod("initializeWithDefaults", Context.class);
            initializeWithDefaults.invoke(null, context);
        } catch (Exception e) {
            Log.e("sthetho", "初始化sthetho失败，sthetho未装载");
        }
    }

    public static Interceptor configureInterceptor() {
        try {
            Class<?> aClass = Class.forName("com.facebook.stetho.okhttp3.StethoInterceptor");
            return (Interceptor) aClass.newInstance();//httpClientBuilder.addNetworkInterceptor();
        } catch (Exception e) {
            Log.e("sthetho", "添加sthetho拦截失败，sthetho未装载");
            return chain -> chain.proceed(chain.request());
        }
    }

}
